package br.pucrs.lognplay;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

import org.apache.log4j.Logger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

import br.pucrs.lognplay.job.CollectorJob;

public class Collector {

	private static final Logger logger = Logger.getLogger(Collector.class);

	private static final String COLLECTOR_JOB_NAME = "COLLECTOR_JOB";

	private static final String COLLECTOR_TRIGGER_NAME = "COLLECTOR_TRIGGER";

	private static final String COLLECTOR_GROUP_NAME = "COLLECTOR_GROUP";

	private static final Integer COLLECTOR_INTERVAL = 15;

	public static void main(String[] arguments) {
		try {
			Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
			scheduler.start();

			// @formatter:off
			JobDetail collectorJob = newJob(CollectorJob.class)
					.withIdentity(COLLECTOR_JOB_NAME, COLLECTOR_GROUP_NAME)
					.build();

			Trigger collectorTrigger = newTrigger()
					.withIdentity(COLLECTOR_TRIGGER_NAME, COLLECTOR_GROUP_NAME)
					.startNow()
					.withSchedule(simpleSchedule()
							.withIntervalInSeconds(COLLECTOR_INTERVAL)
							.repeatForever())
					.build();
			// @formatter:on

			scheduler.scheduleJob(collectorJob, collectorTrigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
}
